package org.example;

import java.awt.*;
import java.io.File;
import java.io.IOException;

public class ExcelOpener {
    public static void openExcelFile(String filePath) {
        try {
            File excelFile = new File(filePath);
            if (excelFile.exists()) {
                if (Desktop.isDesktopSupported()) {
                    Desktop desktop = Desktop.getDesktop();
                    if (desktop.isSupported(Desktop.Action.OPEN)) {
                        desktop.open(excelFile);
                    } else {
                        System.err.println("打开操作不支持");
                    }
                } else {
                    System.err.println("桌面操作不支持");
                }
            } else {
                System.err.println("文件不存在: " + filePath);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 使用示例
    public static void main(String[] args) {
        String excelPath = "D:/订单数据.xlsx";
        openExcelFile(excelPath);
    }
}